package com.lh.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lh.springcloud.alibaba.domain.CommonResult;
import com.lh.springcloud.alibaba.domain.Order;
import com.lh.springcloud.alibaba.myHandler.OrderBlockHandler;
import com.lh.springcloud.alibaba.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //查询订单，用于测试,并加入异常信息
    @GetMapping("/query")
    //如果查询次数过多，则使用此方法写入降级
    @SentinelResource(value = "queryFallback",
    blockHandlerClass = OrderBlockHandler.class, fallback = "queryException")
    public CommonResult queryAll(Order order){
        return orderService.queryAll(order);
    }

    /**
     * 创建订单
     */
    @GetMapping("/create")
    @SentinelResource(value = "createfallback", blockHandlerClass = OrderBlockHandler.class, fallback = "createException")
    public CommonResult create( Order order) {
        orderService.create(order);
        return new CommonResult(200, "订单创建成功!");
    }

}
